﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using TSVNAddin.SVN;
using System.IO;

namespace TSVNAddin.Core
{
	public class ProjectAddedAction
	{
		private readonly PathAddedAction _AddedAction;
		private readonly ProjectItemsRecover _ProjectItemsRecover;
		private readonly IVersionControl _VersionControl;

		public ProjectAddedAction(PathAddedAction addedAction, ProjectItemsRecover projectItemsRecover, IVersionControl versionControl)
		{
			_AddedAction = addedAction;
			_ProjectItemsRecover = projectItemsRecover;
			_VersionControl = versionControl;
		}

		public void Execute(Project project)
		{
			var projectPath = project.FullName;
			_AddedAction.Execute(projectPath);

			string[] paths = _ProjectItemsRecover.GetItemPaths(project);
			foreach (string path in paths)
				_AddedAction.Execute(path);

			string directory = Path.GetDirectoryName(projectPath);
			_VersionControl.AddToIgnoreList(directory, "bin");
			_VersionControl.AddToIgnoreList(directory, "obj");
		}
	}
}
